Home:ALL Converter>compare specific string to a word python

compare specific string to a word python

Ask Time:2018-11-12T00:53:35         Author:user10596917

Json Formatter

say I have a certain string and a list of strings. I would like to append to a new list all the words from the list (of strings) that are exactly like the pattern for example:

list of strings = ['string1','string2'...] 
pattern =__letter__letter_ ('_c__ye_' for instance)

I need to add all strings that are made up of the same letters in the same places as the pattern, and has the same length. so for instance:

new_list = ['aczxyep','zcisyef'...]

I have tried this:

def pattern_word_equality(words,pattern):
list1 = []
for word in words:
    for letter in word:
        if letter in pattern:
            list1.append(word)
return list1

help will be much appreciated :)

Author:user10596917,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/53251010/compare-specific-string-to-a-word-python
yy